/**
 * @version Create on 2012-10-29
 * @author Yinzi Chen
 */

public class AddBinary {

	public String addBinary(String a, String b) {
		int base = 2;
		int n = a.length();
		int m = b.length();
		int len = Math.max(n, m) + 1;
		int p[] = new int[len];
		int q[] = new int[len];
		for (int i = 0; i < n; ++i) {
			p[i + len - n] = a.charAt(i) - '0';
		}
		for (int i = 0; i < m; ++i) {
			q[i + len - m] = b.charAt(i) - '0';
		}
		int c[] = new int[len];
		for (int i = len - 1; i > 0; i--) {
			c[i] += p[i] + q[i];
			c[i - 1] += c[i] / base;
			c[i] %= base;
		}
		String s = "";
		if (c[0] == 1)
			s = "1";
		for (int i = 1; i < len; ++i)
			s += c[i];
		return s;
	}

	public static void main(String[] args) {
		AddBinary a = new AddBinary();
		a.addBinary("11", "1");
	}

}
